package com.god530.l01array;
// lowArray.java
// demosnstrates array class with low-level interface
// to run this program:C>java LowArrayApp
public class LowArray {

	private long[] a;  // ref to array a
	////////////////////////////////////////////
	public LowArray(int size) 
	{ a = new long[size]; }  // create array
	////////////////////////////////////////////
	public void setElem(int index, long value)
	{ a[index] = value; }  // setvalue
	///////////////////////////////////////////
	public long getElem(int index) // get value
	{ return a[index]; }
}

///////////////////////////////////////////////
class LowArrayApp
{
	public static void main(String[] args) {
		LowArray arr;  //reference
		arr = new LowArray(100);  // create a LowArray Object
		int nElems = 0;           // number of items
		int j;					  // loop  variable

		arr.setElem(0, 77);
		arr.setElem(1, 99);
		arr.setElem(2, 44);
		arr.setElem(3, 55);
		arr.setElem(4, 22);
		arr.setElem(5, 88);
		arr.setElem(6, 11);
		arr.setElem(7, 66);
		arr.setElem(8, 33);
		arr.setElem(9, 99);
		nElems = 10;              // now 10 items in array
		for (j = 0; j < nElems; j++) { // display items
			System.out.println(arr.getElem(j) + " ");
		}
		System.out.println("");
		
		
		int searchKey = 26;  // search for data item
		for (j = 0; j < nElems; j++) {  // for each element
			if (arr.getElem(j) == searchKey) {
				break;
			}
		}
		if(j == nElems)
			System.out.println("Can't find " + searchKey);
		else
			System.out.println("Found " + searchKey);
		
		
		// delete value 55
		for (j = 0; j < nElems; j++) {
			if (arr.getElem(j) == 55) {
				break;
			}
		}
		for (int k = j; k < nElems; k++) { //higher one's down
			arr.setElem(k, arr.getElem(k+1));
		}
		nElems--;
		for (j = 0; j < nElems; j++) {
			System.out.println(arr.getElem(j) + " ");
		}
		System.out.println(" ");
		
	}
}

